﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace StudentManagerApplication.Model
{
    class Subject
    {
        public Subject()
        {
        }

        public Subject(int _id, string _subjectname)
        {
            Id = _id;
            SubjectName = _subjectname;
        }

        public Subject(int _id, string _subjectname,int _score,List<Student> _students)
        {
            Id = _id;
            SubjectName = _subjectname;
            Score = _score;
            Students = _students;
        }

        public Subject(int _id, string _subjectname, int _score)
        {
            Id = _id;
            SubjectName = _subjectname;
            Score = _score;
        }

        private int id;

        public int Id
        {
            get { return id; }
            set { id = value; }
        }

        private string subjectname;

        public string SubjectName
        {
            get { return subjectname; }
            set { subjectname = value; }
        }

        private float score;

        public float Score
        {
            get { return score; }
            set { score = value; }
        }

        private List<Student> students;

        internal List<Student> Students
        {
            get { return students; }
            set { students = value; }
        }

        public override bool Equals(object obj)
        {
            return ((Subject)obj).Id == Id;
        }

        public float CountScore()
        {
            float countScore = 0;
            foreach (Student student in students)
            {
                countScore += student.Subjects[Id].Score;
            }
            return countScore;
        }

        public float AvgScore()
        {
            return CountScore() / students.Count;
        }

        public float MaxScore()
        {
            float maxScore = 0;
            foreach (Student student in students)
            {
                maxScore = student.Subjects[Id].Score > maxScore ? student.Subjects[Id].Score : maxScore;
            }
            return maxScore;
        }

        public float MinScore()
        {
            float minScore = float.MaxValue;
            foreach (Student student in students)
            {
                minScore = student.Subjects[Id].Score < minScore ? student.Subjects[Id].Score : minScore;
            }
            return minScore;
        }

        public float PassOdds()
        {
            float passCount = 0;
            foreach (Student student in students)
            {
                passCount = student.Subjects[Id].Score >= 60 ? passCount + 1 : passCount;
            }
            return passCount / students.Count;
        }

        public float GoodOdds()
        {
            int goodCount = 0;
            foreach (Student student in students)
            {
                goodCount = student.Subjects[Id].Score >= 85 ? goodCount + 1 : goodCount;
            }
            return (float)goodCount / students.Count;
        }

        
    }
}
